package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysLog;
import com.gec.model.entity.SysOwner;
import com.gec.model.vo.SysLogQueryVo;
import com.gec.model.vo.SysOwnerQueryVo;
import com.gec.system.service.SysLogService;
import com.gec.system.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author lys
 * @since 2023-12-09
 */
@RestController
@RequestMapping("/admin/system/sysLog/")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;


    @ApiOperation("分页查询日志列表")
    @GetMapping("{page}/{limit}")
    public Result findPage(@PathVariable Long page,
                           @PathVariable Long limit,
                           SysLogQueryVo vo){

        IPage<SysLog> page1 = new Page<>(page,limit);
        page1 = this.sysLogService.selectPageList(page1,vo);
        return Result.ok(page1);
    }

    @ApiOperation("添加日志")
    @PostMapping("addLog")
    public Result addLog(@RequestBody SysLog sysLog){

        boolean save = this.sysLogService.save(sysLog);
        if (save){
            return Result.ok();
        }

        return Result.fail();
    }

    @ApiOperation("根据id删除日志信息")
    @DeleteMapping("removeLogById/{id}")
    public Result removeOwnerById(@PathVariable Long id){

        boolean b = this.sysLogService.removeById(id);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

    @ApiOperation("根据ids批量删除日志信息")
    @DeleteMapping("removeLogByIds")
    public Result removeOwnerByIds(@RequestBody List<Long> ids){

        boolean b = this.sysLogService.removeByIds(ids);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

}

